<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{log_name} : {log_account_no}</title>
<link rel="shortcut icon" href="{dir_image}favicon.ico">
<link rel="stylesheet" type="text/css" href="{dir_css}Global.css" />
<link rel="stylesheet" type="text/css" href="{dir_css}Popup.css" />
<link rel="stylesheet" type="text/css" href="{dir_css}Registrar.css" />

<script type="text/javascript" src="{dir_js}jquery.min.js"></script>
<script type="text/javascript" src="{dir_js}Global.js"></script>
</head>

<body>
<!-- POPUP -->{page_popup}<!-- POPUP END -->
<!-- TOP HEADER -->{page_header}<!-- TOP HEADER END -->
	<div class="main-content">
		<input type="hidden" id="record_saved" value="{record_saved}"/>
		<table width="0" border="0" cellspacing="0" cellpadding="0">
			<tr valign="top" align="left">
				<td width="220">
					{dean_sub_menu}
				</td>
				<td width="755">
					<div class="page-sub-content">
						<div class="float-right-back"><a href="?page=Students"><img src="{dir_image}icon/back.png" border="0"/></a></div>	
						<div class="ann-top-label">Students Record</div>
						<table width="0" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td class="reg-student-enroll-td" width="110"><strong>Student #</strong></td>
								<td class="reg-student-enroll-td">:</td>
								<td class="reg-student-enroll-td">{stud_no}</td>
							</tr>
							<tr>
								<td class="reg-student-enroll-td"><strong>Name</strong></td>
								<td class="reg-student-enroll-td">:</td>
								<td class="reg-student-enroll-td">{last_name} {first_name} {middle_name}</td>
							</tr>
							<tr>
								<td class="reg-student-enroll-td"><strong>Department</strong></td>
								<td class="reg-student-enroll-td">:</td>
								<td class="reg-student-enroll-td">{dept_desc}</td>
							</tr>
							<tr>
								<td class="reg-student-enroll-td"><strong>Course</strong></td>
								<td class="reg-student-enroll-td">:</td>
								<td class="reg-student-enroll-td">{course_desc}</td>
							</tr>
							<tr>
								<td colspan="2"></td>
								<td><div class="enrollment-more-details"  onclick="popupRequest('show', 'StudentProfile', 'Student Profile', '390', '500', '{stud_id}');">More Details</div></td>
							</tr>
						</table>
						<div class="div-reg-transfery">
							<ul class="ul-reg-transfery">
								<li class="li-reg-transfery" onclick="Freshmen();" id="li_freshment">Freshmen</li>
								<li class="li-reg-transfery" onclick="transfery();" id="li_transferee">Transferee</li>
							</ul>
						</div>
						<div class="div-reg-pointer" id="click_type_reg_transfer"></div>
						<form method="post" enctype="multipart/form-data" action="" onsubmit="return validateForm()" >
							<div class="enrollment-popup" id="view_enrollment_popup"><!--  display-none -->
								<input type="hidden" id="is_regular" name="is_regular"/>
								<input type="hidden" id="syear" value="{syear}"/>
								<input type="hidden" id="year_id" name="year_id" value="{year_id}"/>
								<input type="hidden" name="list_subj_taken" id="list_subj_taken" value=""/>
								<input type="hidden" name="active_subj_taken" id="active_subj_taken" value="{active_subj_taken}"/>
								<input type="hidden" id="sem_linker_id" value="{sem_linker_id}"/>
								<input type="hidden" id="stud_id" value="{stud_id}"/>
								<input type="hidden" id="course_id" value="{course_id}"/>
								<input type="hidden" id="course_desc" value="{course_desc}"/>
								<input type="hidden" id="sem_desc" value="{sem_desc}"/>
								<input type="hidden" id="redirect" value="{redirect}"/>
								<input type="hidden" id="active_subj"  />
								<input type="hidden" id="is_freshmen" value="{is_freshmen}"/>
								
								<div id="enrollment_popup"></div>
							</div>
							<input type="submit" name="subButton" class="enroll-save-button" value="Save"/>
						</form>
					</div>
				</td>
			</tr>
		</table>
		
	</div>
<!-- FOOTER -->{page_footer}<!-- FOOTER -->
<script type="text/javascript">
	
	$(document).ready(function() {
		
		if ( $('#is_freshmen').val() > 0 ) {
			transfery();
			$('#li_freshment').hide();
			$('#li_transferee').show();
			$('#is_regular').val('N');
		}
		else {
			Freshmen();
			$('#li_freshment').show();
			$('#li_transferee').hide();
			$('#is_regular').val('Y');
		}
		
		/*if ( $('#redirect').val() == 1 ) transfery();
			else Freshmen();*/
	});
	
	function validateForm() {
		var list_subj_taken = $('#list_subj_taken').val();
		if (list_subj_taken==null || list_subj_taken=="") {
				alert("Please select subject you want to register.");
		  		return false;
		}
		return true;
	}
		
	function studNewEnrollyValue(strID, strValue) {
		var list_subj_taken = $('#list_subj_taken');
		
		if (list_subj_taken.val() == '') 
			list_subj_taken.val(strValue);	// Auto Add Value
		else
			list_subj_taken.val(list_subj_taken.val() + ', ' + strValue);
			
		strArray = list_subj_taken.val().split(', ');
		if ( $('#hidden_subj_id'+strID).val() == 0 ) {
			$('#list_subj_taken').val(strArray.join(", "));
			$('#hidden_subj_id'+strID).val(1);
			$('#but_subj_id'+strID).attr('src','{dir_image}icon/checkbox_check.png');
		}
		else {
			arr = $.grep(strArray, function(n, i){ return (n != strValue); });
			list_subj_taken.val(arr.join(", "));
			$('#hidden_subj_id'+strID).val(0);
			$('#but_subj_id'+strID).attr('src','{dir_image}icon/checkbox_uncheck.png');
		}
		
	}
	
		function Freshmen() {
			var sem_linker_id 	   = $('#sem_linker_id').val();
			var sem_desc 		   = $('#sem_desc').val();
			var enrollment_popup   = $('#enrollment_popup');
			var list_subj_taken	   = $('#list_subj_taken');
			var active_subj_taken  = $('#active_subj_taken');
			
			enrollment_popup.html('');
			list_subj_taken.val('');
			var sem_enrol_value = '';
			$.post('request.php', {AJAXPost:'coRequisite', strSubjLinkerID:sem_linker_id}, function(res) {
				if (res == 0) {
					enrollment_popup.append('<div class="enrollment-label">' + sem_desc + '</div><div class="ajax-enrollment-value">No Record Found.</div>');
				}
				else {
					active_subj_taken.val(sem_linker_id);
					enrollment_popup.append('<div class="enrollment-label">' + sem_desc + ' - SY: ' + $('#syear').val() + '</div>');
					$.each( res, function( key, value ) {
						sem_enrol_value = sem_enrol_value + value['subj_idPK'] + ',';
						if (list_subj_taken.val() == '')
							list_subj_taken.val(value['subj_idPK']);
						else
							list_subj_taken.val(list_subj_taken.val() + ', ' + value['subj_idPK']);
						
						if ( value['total_units'] > 0 )
							enrollment_popup.append('<div class="enrollment-lock"><input type="hidden" id="hidden_subj_id' + value['subj_idPK'] + '" value="1"/><img src="{dir_image}icon/checkbox_lock.png" border="0"/> ' + value['subj_desc'] + ' (' + value['subj_code'] +')</div>');
						else
							enrollment_popup.append('<div class="enrollment-lock"><input type="hidden" id="hidden_subj_id' + value['subj_idPK'] + '" value="1"/><img id="but_subj_id' + value['subj_idPK'] + '" src="{dir_image}icon/checkbox_check.png" border="0" onclick="studNewEnrollyValue(\'' + value['subj_idPK'] + '\', \'' + value['subj_idPK'] +'\');" class="cursor-pointer"/> ' + value['subj_desc'] + ' (' + value['subj_code'] +')</div>');
					});
				}
				$('#click_type_reg_transfer').text('Freshmen');
				$('#sem_enrollees_value').val(sem_enrol_value);
				$('#view_enrollment_popup').slideDown();
			}, 'json');
			
		}
	
	function transfery() {
		$('#click_type_reg_transfer').text('Transferee');
		$('#list_subj_taken').val('');
		var enrollment_popup   	= $('#enrollment_popup');
		enrollment_popup.html('').append('<div class="transfery-menu-button">'+
												'<div class="transfery-menu-button-link" onclick="creditSubjectEnroll();"><img src="{dir_image}icon/header.png" border="0" width="11" height="11"/> Credit Subjects</div>'+
												'<div class="transfery-menu-button-link" onclick="enrollSubjectEnroll();"><img src="{dir_image}icon/reports.png" border="0" width="11" height="11"/> Register Subjects</div>'+
											'</div>'+
											'<div class="ajax-enrollment-value" id="enrollment_value_stud_subj"></div>');
		creditSubjectEnroll();
	}
	
		function creditSubjectEnroll() {
			var enrollment_value_stud_subj	= $('#enrollment_value_stud_subj');
			var stud_id   					= $('#stud_id').val();
			var course_id   				= $('#course_id').val();
			var course_desc   				= $('#course_desc').val();
			enrollment_value_stud_subj.html('').append('<div>'+
															'<a href="?page=StudentEnrollment&studid=' + stud_id + '&r=1&hash={hash}"><div class="refresh-credit-subject"><img src="{dir_image}icon/refresh.png" border="0" width="11" height="11"/> REFRESH</div></a>'+
														'</div>'+
														'<div class="stud-grade-subj-list"><div id="stud_grade_subj_list"></div></div>');
			studentGradeSubjListing(stud_id, course_id);
		}
	
		function enrollSubjectEnroll() {
			$('#list_subj_taken').val('');
			var enrollment_value_stud_subj	= $('#enrollment_value_stud_subj');
			var stud_id   					= $('#stud_id').val();
			var course_id   				= $('#course_id').val();
			var course_desc   				= $('#course_desc').val();
			enrollment_value_stud_subj.html('').append('<div class="here-credit-subject">'+
															'<a href="?page=StudentEnrollment&studid=' + stud_id + '&r=1&hash={hash}"><div class="refresh-credit-subject"><img src="{dir_image}icon/refresh.png" border="0" width="11" height="11"/> REFRESH</div></a>'+
															'<div class="click-here-credit-subject-units" id="label_semester_units">Please select Year/Semester you want to register.</div>'+
														'</div>'+
														'<div class="stud-grade-subj-list">'+
														'<div id="stud_grade_subj_enroll_list"></div></div>');
			gradeSubjEnrollListing(stud_id, course_id);
		}
		
		function getRequisiteData() {
			$.post('request.php', {AJAXPost:'requisiteSubjCourse', course_id:$('#course_id').val()}, function(res) {
				strArrayActiveSubj = $('#active_subj').val().split('-');
				$.each(res, function(first_key, first_value) {
					$.each(first_value, function(second_key, second_value) {
						strResultInArray = $.inArray(second_value['pre_req'], strArrayActiveSubj);
						if(strResultInArray < 0 || second_value['pre_req'] == '') {
							$('#button_enroll_get_data'+second_value['subj_idFK']).html('<img src="{dir_image}icon/checkbox_remove.png" border="0" />');
							$('#transfery_desc_code'+second_value['subj_idFK']).attr('onclick', false);
						}
					});
				});
			}, 'json');
		}
		
			// Transfery > List of Semesters
			function gradeSubjEnrollListing(strStudID, strCourseID) {
				var stud_grade_subj_enroll_list = $('#stud_grade_subj_enroll_list');
				var stud_id   					= $('#stud_id').val();
				var year_id   					= $('#year_id').val();
				stud_grade_subj_enroll_list.html('');
				//$.post('request.php', {AJAXPost:'preRequisiteEnrolled', strCourseID:strCourseID, strStudID:strStudID}, function(res) {
				$.post('request.php', {AJAXPost:'getSemesterIrregular', strCourseID:strCourseID, studID:stud_id, yearID:year_id}, function(res) {
					$.each( res, function( key, value ) {
						stud_grade_subj_enroll_list.append('<div class="enrollment-label cursor-pointer" id="enroll_trans_select_sem' + value['sem_linker_idPK'] + '" onclick="selectGradeTransfery(\'' + value['sem_desc'] + '\', \'' + value['sem_linker_idPK'] + '\');">'+
																'<img src="{dir_image}icon/check.png" border="0"/> ' + value['sem_desc'] + '</div>' +
															'</div><div id="enoll_transfery_sem_sub' + value['sem_linker_idPK'] + '"></div>');
					});
					
				}, 'json');
			}
				// Transfery > Compute Total Units Per Semester
				function selectGradeTransfery(strDesc, strSemLinker) {
					
					$('#active_subj_taken').val(strSemLinker);
					
					var strStudID = $('#stud_id').val();
					var strCourseID = $('#course_id').val();
					$.post('request.php', {AJAXPost:'gradeTotalUnitsPerSemester', sem_linker_id:strSemLinker}, function(res) {
						$('#click_type_reg_transfer').html('<span onclick="enrollSubjectEnroll();" class="transfery-class-linker">Transferee</span>' +
														   '<input type="hidden" id="select_transfery_total_units" value="' + res.total_units + '">'+
														   '<img src="{dir_image}icon/next.png" border="0" /> ' + strDesc);
						$('#label_semester_units').html('Units: <strong><span id="subj_units_span">0</span></strong>/<span id="total_units_span"><strong>' + res.total_units + '</strong></span>');
						gradeSubjEnrollListingSubjects(strStudID, strCourseID, strSemLinker);
					}, 'json');
				}
				
					// Transfery > Select Semester > Enroll Subjects
					function gradeSubjEnrollListingSubjects(strStudID, strCourseID, strSemLinker) {
						var stud_grade_subj_enroll_list = $('#stud_grade_subj_enroll_list');
						stud_grade_subj_enroll_list.html('');
						var subj_transfery_first_key = '';
						$.post('request.php', {AJAXPost:'GradeSubjEnrollSemester', stud_id:strStudID, course_id:strCourseID, sem_linker_id:strSemLinker}, function(res) {
							
							$.each(res, function(first_key, first_value) {
								
								getStudentSemesterDesc(first_key, 'sem_stud_grade_enroll_list');
								subj_transfery_first_key += first_key + ',';
								stud_grade_subj_enroll_list.append('<div class="enrollment-label" id="sem_stud_grade_enroll_list' + first_key + '"></div>');
								stud_grade_subj_enroll_list.append('<table width="0" border="0" cellspacing="0" cellpadding="0">');
								$.each(first_value, function(second_key, second_value) {
									
									stud_grade_subj_enroll_list.append('<tr class="hover-light">'+
																			'<td width="15" height="16">'+
																				'<div id="button_enroll_get_data' + second_value['subj_idPK'] + '">'+
																					'<input type="hidden" class="hidden_trans_subj_id" id="hidden_trans_subj_id' + second_value['subj_idPK'] + '" value="0"/>'+
																					'<input type="hidden" id="unit_number' + second_value['subj_idPK']  + '" value="' + Math.abs(second_value['total_units'])  + '">'+
																					'<img id="but_trans_subj_id' + second_value['subj_idPK'] + '" src="{dir_image}icon/checkbox_uncheck.png" border="0" class="but_trans_subj_id cursor-pointer" onclick="studNewTransferyEnrollyValue(\'' + second_value['subj_idPK'] + '\', \'' + second_value['subj_idPK'] +'\', \'' + Math.abs(second_value['total_units'])  + '\');" />'+
																				'<div>'+
																			'</td>'+
																			'<td width="500">'+
																				'<span class="transfery_desc_code cursor-pointer" id="transfery_desc_code' + second_value['subj_idPK'] + '" onclick="studNewTransferyEnrollyValue(\'' + second_value['subj_idPK'] + '\', \'' + second_value['subj_idPK'] +'\', \'' + Math.abs(second_value['total_units'])  + '\');">' + second_value['subj_desc'] + ' (' + second_value['subj_code'] +')</span>'+
																			'</td>'+
																			'<td width="100">' + Math.abs(second_value['total_units']) + ' Units</td></tr>');
									
								});
								stud_grade_subj_enroll_list.append('</table>');
							});
							
							getRequisiteData();
							
						}, 'json');
					}
				
				// Transfery > Input Value to Input Text Box
				function studNewTransferyEnrollyValue(strID, strValue, strSubjUnits) {
					
					var subj_units_span  = $('#subj_units_span').text();
					var total_units_span = $('#total_units_span').text(); 
					
					sum_total_comput_units  = parseInt(subj_units_span) + parseInt(strSubjUnits);
					diff_total_comput_units = parseInt(subj_units_span) - parseInt(strSubjUnits);
					
					var list_subj_taken  = $('#list_subj_taken');
					
					if ( sum_total_comput_units <= total_units_span ) {
						if (list_subj_taken.val() == '') 
							list_subj_taken.val(strValue);	// Auto Add Value
						else
							list_subj_taken.val(list_subj_taken.val() + ', ' + strValue);
					}
					
					strArray = list_subj_taken.val().split(', ');
					if ( $('#hidden_trans_subj_id'+strID).val() == 0 ) {
						if ( sum_total_comput_units <= total_units_span ) {
							$('#subj_units_span').text(sum_total_comput_units);
							$('#list_subj_taken').val(strArray.join(", "));
							$('#hidden_trans_subj_id'+strID).val(1);
							$('#but_trans_subj_id'+strID).attr('src','{dir_image}icon/checkbox_check.png');
						}
					}
					else {
						arr = $.grep(strArray, function(n, i){ return (n != strValue); });
						list_subj_taken.val(arr.join(", "));
						$('#hidden_trans_subj_id'+strID).val(0);
						$('#but_trans_subj_id'+strID).attr('src','{dir_image}icon/checkbox_uncheck.png');
						$('#subj_units_span').text(diff_total_comput_units);
					}
					
				}
					
		// Transfery > Credit Subject Listing
		function studentGradeSubjListing(strStud, strCourse) {
			var stud_grade_subj_list = $('#stud_grade_subj_list');
			stud_grade_subj_list.html('');
			$.post('request.php', {AJAXPost:'StudentGradeSubjListing', stud_id:strStud, course_id:strCourse}, function(res) {
				
				var subj_active_list = '';
				$.each(res, function(first_key, first_value) {
					
					getStudentSemesterDesc(first_key, 'sem_stud_grade_list');
					
					stud_grade_subj_list.append('<div class="enrollment-label" id="sem_stud_grade_list' + first_key + '"></div>');
					
					stud_grade_subj_list.append('<table width="0" border="0" cellspacing="0" cellpadding="0">');
					
					$.each(first_value, function(second_key, second_value) {
						subj_active_list += second_value['subj_idPK'] + '-';
						stud_grade_subj_list.append('<tr><td width="15" height="16"><img src="{dir_image}icon/grades.png" border="0"/></td><td width="500">' + second_value['subj_desc'] + ' (' + second_value['subj_code'] +')</td><td width="75"><strong>' + second_value['grade'] + '</strong></td><td width="50">' + second_value['equivalence'] + '</td>');
					
					});
					
					stud_grade_subj_list.append('</table>');
				
				});
				
				$('#active_subj').val(subj_active_list);
				
			}, 'json');
		}
		
		function getStudentSemesterDesc(strSem, strDdivID) {
			$.post('request.php', {AJAXPost:'Semester', sem_id:strSem}, function(res) {
				$('#'+strDdivID+strSem).text(res.sem_desc)
			}, 'json');
		}
	
</script>
</body>
</html>
